from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-04-30 14:02:07.675324
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Sat, 30, Apr, 2022
Time: 14:02:13
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.1183
Nobs: 642.000 HQIC: -49.5012
Log likelihood: 7859.24 FPE: 2.49119e-22
AIC: -49.7441 Det(Omega_mle): 2.16767e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.326134 0.061837 5.274 0.000
L1.Burgenland 0.105111 0.039344 2.672 0.008
L1.Kärnten -0.110273 0.020631 -5.345 0.000
L1.Niederösterreich 0.196492 0.082204 2.390 0.017
L1.Oberösterreich 0.118470 0.081134 1.460 0.144
L1.Salzburg 0.258618 0.041815 6.185 0.000
L1.Steiermark 0.043789 0.054977 0.797 0.426
L1.Tirol 0.105180 0.044367 2.371 0.018
L1.Vorarlberg -0.063845 0.039205 -1.629 0.103
L1.Wien 0.026286 0.071879 0.366 0.715
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.053018 0.132196 0.401 0.688
L1.Burgenland -0.032866 0.084109 -0.391 0.696
L1.Kärnten 0.040205 0.044106 0.912 0.362
L1.Niederösterreich -0.189601 0.175736 -1.079 0.281
L1.Oberösterreich 0.448017 0.173450 2.583 0.010
L1.Salzburg 0.285591 0.089393 3.195 0.001
L1.Steiermark 0.105824 0.117530 0.900 0.368
L1.Tirol 0.313898 0.094848 3.309 0.001
L1.Vorarlberg 0.021959 0.083813 0.262 0.793
L1.Wien -0.037564 0.153664 -0.244 0.807
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189827 0.031673 5.993 0.000
L1.Burgenland 0.090459 0.020152 4.489 0.000
L1.Kärnten -0.007951 0.010567 -0.752 0.452
L1.Niederösterreich 0.248850 0.042104 5.910 0.000
L1.Oberösterreich 0.157227 0.041557 3.783 0.000
L1.Salzburg 0.040530 0.021418 1.892 0.058
L1.Steiermark 0.025401 0.028159 0.902 0.367
L1.Tirol 0.086972 0.022724 3.827 0.000
L1.Vorarlberg 0.054080 0.020081 2.693 0.007
L1.Wien 0.116058 0.036816 3.152 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.112571 0.031836 3.536 0.000
L1.Burgenland 0.045495 0.020256 2.246 0.025
L1.Kärnten -0.014370 0.010622 -1.353 0.176
L1.Niederösterreich 0.180283 0.042321 4.260 0.000
L1.Oberösterreich 0.327301 0.041771 7.836 0.000
L1.Salzburg 0.101648 0.021528 4.722 0.000
L1.Steiermark 0.110393 0.028304 3.900 0.000
L1.Tirol 0.098020 0.022842 4.291 0.000
L1.Vorarlberg 0.059313 0.020184 2.939 0.003
L1.Wien -0.021394 0.037006 -0.578 0.563
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.115121 0.059261 1.943 0.052
L1.Burgenland -0.043121 0.037705 -1.144 0.253
L1.Kärnten -0.046280 0.019772 -2.341 0.019
L1.Niederösterreich 0.144570 0.078780 1.835 0.066
L1.Oberösterreich 0.157264 0.077755 2.023 0.043
L1.Salzburg 0.283684 0.040074 7.079 0.000
L1.Steiermark 0.055934 0.052687 1.062 0.288
L1.Tirol 0.165644 0.042519 3.896 0.000
L1.Vorarlberg 0.096357 0.037572 2.565 0.010
L1.Wien 0.073089 0.068885 1.061 0.289
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060281 0.046655 1.292 0.196
L1.Burgenland 0.030375 0.029684 1.023 0.306
L1.Kärnten 0.051474 0.015566 3.307 0.001
L1.Niederösterreich 0.205761 0.062021 3.318 0.001
L1.Oberösterreich 0.322903 0.061214 5.275 0.000
L1.Salzburg 0.038248 0.031549 1.212 0.225
L1.Steiermark 0.007070 0.041479 0.170 0.865
L1.Tirol 0.130409 0.033474 3.896 0.000
L1.Vorarlberg 0.063824 0.029579 2.158 0.031
L1.Wien 0.090543 0.054231 1.670 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173237 0.056013 3.093 0.002
L1.Burgenland 0.006008 0.035638 0.169 0.866
L1.Kärnten -0.065229 0.018688 -3.490 0.000
L1.Niederösterreich -0.096565 0.074462 -1.297 0.195
L1.Oberösterreich 0.203808 0.073493 2.773 0.006
L1.Salzburg 0.055114 0.037877 1.455 0.146
L1.Steiermark 0.239574 0.049799 4.811 0.000
L1.Tirol 0.501854 0.040188 12.488 0.000
L1.Vorarlberg 0.061053 0.035513 1.719 0.086
L1.Wien -0.076460 0.065110 -1.174 0.240
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.147070 0.062127 2.367 0.018
L1.Burgenland 0.004958 0.039528 0.125 0.900
L1.Kärnten 0.060361 0.020728 2.912 0.004
L1.Niederösterreich 0.184807 0.082590 2.238 0.025
L1.Oberösterreich -0.062217 0.081515 -0.763 0.445
L1.Salzburg 0.208025 0.042012 4.952 0.000
L1.Steiermark 0.134441 0.055235 2.434 0.015
L1.Tirol 0.068571 0.044575 1.538 0.124
L1.Vorarlberg 0.144869 0.039389 3.678 0.000
L1.Wien 0.110994 0.072216 1.537 0.124
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.378412 0.036572 10.347 0.000
L1.Burgenland -0.001173 0.023269 -0.050 0.960
L1.Kärnten -0.021856 0.012202 -1.791 0.073
L1.Niederösterreich 0.211304 0.048618 4.346 0.000
L1.Oberösterreich 0.226026 0.047985 4.710 0.000
L1.Salzburg 0.038836 0.024731 1.570 0.116
L1.Steiermark -0.013967 0.032515 -0.430 0.668
L1.Tirol 0.095080 0.026240 3.624 0.000
L1.Vorarlberg 0.052764 0.023187 2.276 0.023
L1.Wien 0.036775 0.042511 0.865 0.387
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036155 0.113719 0.173235 0.140836 0.102467 0.085423 0.037796 0.209793
Kärnten 0.036155 1.000000 -0.021200 0.134309 0.052661 0.090140 0.442199 -0.060469 0.092506
Niederösterreich 0.113719 -0.021200 1.000000 0.323097 0.129996 0.284128 0.075596 0.162522 0.296599
Oberösterreich 0.173235 0.134309 0.323097 1.000000 0.222223 0.310186 0.169017 0.150204 0.249815
Salzburg 0.140836 0.052661 0.129996 0.222223 1.000000 0.132259 0.097589 0.112882 0.130029
Steiermark 0.102467 0.090140 0.284128 0.310186 0.132259 1.000000 0.140088 0.120996 0.049253
Tirol 0.085423 0.442199 0.075596 0.169017 0.097589 0.140088 1.000000 0.069819 0.149791
Vorarlberg 0.037796 -0.060469 0.162522 0.150204 0.112882 0.120996 0.069819 1.000000 0.006535
Wien 0.209793 0.092506 0.296599 0.249815 0.130029 0.049253 0.149791 0.006535 1.000000